using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class UserPostUploadVote : BaseItem
    {
        protected UserPostUploadVote() : base() { }
        protected UserPostUploadVote(Hashtable table) : base(table) { }
        protected UserPostUploadVote(Hashtable table, List<UserPostUploadVote> collection) : base(table, collection) { }

        public static UserPostUploadVote CreateInstance(int userId, int userPostUploadId)
        {
            UserPostUploadVote tmp = new UserPostUploadVote();
            tmp.userId = userId;
            tmp.userPostUploadId = userPostUploadId;
            return tmp;
        }

        private static UserPostUploadVote Get(Hashtable table)
        {
            if (table != null)
            {
                return new UserPostUploadVote(table);
            }
            else
            {
                return null;
            }
        }

        private static List<UserPostUploadVote> Get(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<UserPostUploadVote> tmp = new List<UserPostUploadVote>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new UserPostUploadVote(table, tmp));
                }
                return tmp;
            }
            else
            {
                return null;
            }
        }

        public static UserPostUploadVote GetByUserIdAndUploadId(int userId, int userPostUploadId)
        {
            UserPostUploadVoteDal dal = new UserPostUploadVoteDal();
            return Get(dal.GetByUserIdAndUploadId(userId, userPostUploadId));
        }

        public static List<UserPostUploadVote> GetAllByUserIdAndPostId(int userId, int postId)
        {
            UserPostUploadVoteDal dal = new UserPostUploadVoteDal();
            return Get(dal.GetAllByUserIdAndPostId(userId, postId));
        }

        protected override Base CreateDal()
        {
            return new UserPostUploadVoteDal();
        }

        public new void Update()
        {
            base.Update();
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            if (IsNewRecord)
            {
                created = DateTime.Now;
            }
            ((UserPostUploadVoteDal)dal).Update(ref id, userId, userPostUploadId, ref title, ref postId, score, created, ref concurencyId);
        }

        protected override void Load(Hashtable table)
        {
            id = (int)table[UserPostUploadVoteDal.Fields.Id];
            userId = (int)table[UserPostUploadVoteDal.Fields.UserId];
            userPostUploadId = (int)table[UserPostUploadVoteDal.Fields.UserPostUploadId];
            title = (string)table[UserPostUploadVoteDal.Fields.Title];
            postId = (int)table[UserPostUploadVoteDal.Fields.PostId];
            score = (decimal)table[UserPostUploadVoteDal.Fields.Score];
            created = (DateTime)table[UserPostUploadVoteDal.Fields.Created];
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private int userId;
        public int UserId
        {
            get { return userId; }
        }
	

        private int userPostUploadId;
        public int UserPostUploadId
        {
            get { return userPostUploadId; }
        }

        private string title;
        public string Title
        {
            get { return title; }
        }
	
        private int postId;
        public int PostId
        {
            get { return postId; }
        }
	

        private decimal score;
        public decimal Score
        {
            get { return score; }
            set { score = value; }
        }
	
        private DateTime created;
        public DateTime Created
        {
            get { return created; }
        }



    }
}
